// cnpm install axios --save
// 1 引入axios  
import axios from 'axios'


//- 接口基准地址：`http://ludir.cn:8888/api/private/v1/`
// - 服务端已开启 CORS 跨域支持
// - API V1 认证统一使用 Token 认证
// - 需要授权的 API ，必须在请求头中使用 `Authorization` 字段提供 `token` 令牌
// - 使用 HTTP Status Code 标识状态
// - 数据返回格式统一使用 JSON 
let baseUrl = 'http://localhost:3000';

axios.defaults.baseURL = baseUrl;
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';




    // Add a request interceptor
    // 请求拦截 (在发送和接受请求时拦截做处理)
    // let AUTH_TOKEN = window.localStorage.getItem('myToken') || ''

    // axios.interceptors.request.use(function (config) {
    //     // Do something before request is sent
    //     // console.log(config);

    //       if (config.url.includes('1106975712662')) {
    //         // 用别人的
    //         config.baseURL = 'https://www.liulongbin.top:8888/api/private/v1/'
    //         config.headers['Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE2Mzg5MjU4MDUsImV4cCI6MTYzOTAxMjIwNX0.R2S3WJp6i1DStWIKuDh8ffpEAbpOlNPt_DvJ-49MHZo'
    //       } else {
    //     config.baseURL = 'http://ludir.cn:8888/api/private/v1/'

    //     config.headers['Authorization'] = AUTH_TOKEN; // 在发送请求之前在请求头配置token 
    //       }



    //       return config;
    // }, function (error) {
    //     // Do something with request error
    //     return Promise.reject(error);
    // });

    // // Add a response interceptor
    // // 响应拦截

    // axios.interceptors.response.use(function (response) {
    //     // Do something with response data
    //     // console.log(response);
    //     //  response:{data meta}


    //     return response.data;

    // }, function (error) {
    //     // Do something with response error
    //     return Promise.reject(error);
    // });
// =======
// 为了让接受到的data减少一层嵌套
    axios.interceptors.response.use(function (response) {
        // Do something with response data
        // console.log(response);
        //  response:{data meta}


        // return response.data;

        return response

    }, function (error) {
        // Do something with response error
        return Promise.reject(error);
    });
// >>>>>>> origin/xwz

// 封装统一api  
// 登录请求
// export let getLogin=(params)=>{
//     return axios.post('login',params)
// }
// 注册请求
export let getZhuce = (params) => axios.post('register', params)
export let getLogin = (params) => axios.post('login', params)
export let getHouse = (params={}) =>axios.get('houses')

// 根据关键字查询房源
export let getHouseByWord = (params) =>axios.get("selecthouses",{params})



export let getgoods = (params) =>axios.get("getgoods")
export let getgoodstype = (params) =>axios.get("getgoodstype",{params})

// 查询id为n详细信息
export let getgoodsinformation = (params) =>axios.get("getgoodsimformation",{params})

//获取list
export let getlist = (params) =>axios.get("getlistAll",{params})
// 获取id为n订单
export let getUserlist = (params) =>axios.get("getlist",{params})
// 添加用户订单
export let getAddUserlist = (params) =>axios.get("addlist",{params})


export let getHouseByZhujin =(params) => axios.get('zhujin',{params})

//判断用户是否收藏该商品
export let getWhetherUserCollectGoods =(params) => axios.get('whetherUserCollectGoods',{params})


// 收藏goods
export let UserCollectGoods =(params) => axios.get('userCollectGoods',{params})
// 删除收藏
export let UserdeleteCollectGoods =(params) => axios.get('userdeleteCollectGoods',{params})


// 获取购物车
export let getgwc = (params) =>axios.get("getgwc",{params})
// 添加购物车
export let addgwc = (params) =>axios.get("addgwc",{params})
// 修改数量
export let updategwcnum = (params) =>axios.get("updategwcnum",{params})




// export let getHouseByZhujin =(params) => axios.get('zhujin',{params})
// 根据筛选查房源
 export let getAfterShaixuan = (params) =>axios.get('shaixuan',{params})



export let getUsers =(params) => axios.get('user',{params})

